import { Button, Component, EventHandheld, EventHandler, Node } from "cc";


export class ViewComponent extends Component {

    protected _viewCtrl: any = null;
    set viewCtrl(val: any) {
        this._viewCtrl = val;
    }

    protected onLoad(): void {
        const btn_close = this.node.getChildByName('btn_close')?.getComponent(Button);
        if (btn_close) {
            this.addClickEvent(btn_close, this.close, this)
        }
    }

    dispose(): void {
        throw new Error('Method not implemented.');
    }

    close(): void {
        this._viewCtrl.close();
    }

    addClickEvent(btn: Button, handler: Function, target: any): void {
        btn.node.on(Button.EventType.CLICK, handler, target);
    }


}